{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 1: Write your name\n",
    "\n",
    "1. Make two string variables, one with your first name and one with your last name.\n",
    "2. Concatenate both strings to form your full name and [assign](https://github.com/dlab-berkeley/python-intensive/blob/master/Glossary.md#assign) it to a variable.\n",
    "3. Assign a new variable that has your full name in all upper case.\n",
    "4. Slice that string to get your first name again."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "JOHN\n"
     ]
    }
   ],
   "source": [
    "first_name = \"John\"\n",
    "last_name = \"Doe\"\n",
    "full_name = first_name + \" \" + last_name\n",
    "full_name_upper = full_name.upper()\n",
    "print(full_name_upper[:len(first_name)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 2: Try seeing what the following string methods do:\n",
    "\n",
    "    * `split`\n",
    "    * `join`\n",
    "    * `replace`\n",
    "    * `strip`\n",
    "    * `find`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 3: Working with strings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Below is a string of Edgar Allen Poe's \"A Dream Within a Dream\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "poem = '''Take this kiss upon the brow!\n",
    "And, in parting from you now,\n",
    "Thus much let me avow —\n",
    "You are not wrong, who deem\n",
    "That my days have been a dream;\n",
    "Yet if hope has flown away\n",
    "In a night, or in a day,\n",
    "In a vision, or in none,\n",
    "Is it therefore the less gone?  \n",
    "All that we see or seem\n",
    "Is but a dream within a dream.\n",
    "\n",
    "I stand amid the roar\n",
    "Of a surf-tormented shore,\n",
    "And I hold within my hand\n",
    "Grains of the golden sand —\n",
    "How few! yet how they creep\n",
    "Through my fingers to the deep,\n",
    "While I weep — while I weep!\n",
    "O God! Can I not grasp \n",
    "Them with a tighter clasp?\n",
    "O God! can I not save\n",
    "One from the pitiless wave?\n",
    "Is all that we see or seem\n",
    "But a dream within a dream?'''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What is the difference between `poem.strip(\"?\")` and `poem.replace(\"?\", \"\")` ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "657 656 653\n"
     ]
    }
   ],
   "source": [
    "print(len(poem), len(poem.strip(\"?\")), len(poem.replace(\"?\", \"\")) )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "At what index does the word \"*and*\" first appear? Where does it last appear?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "314\n",
      "407\n"
     ]
    }
   ],
   "source": [
    "print(poem.find(\"and\"))\n",
    "print(poem.rfind(\"and\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How can you answer the above accounting for upper- and lowercase?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30\n",
      "407\n"
     ]
    }
   ],
   "source": [
    "print(poem.lower().find(\"and\"))\n",
    "print(poem.lower().rfind(\"and\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
